package com.aegis.common.exception;

import cn.hutool.core.util.StrUtil;
import cn.hutool.http.HttpStatus;
import com.aegis.common.web.IResponseEnum;

/**
 * 异常基类
 */
public class BaseException extends RuntimeException {

    private static final long serialVersionUID = 1L;

    /**
     * 错误码
     */
    protected int code;

    /**
     * 错误信息
     */
    protected String message;

    /**
     *
     */
    protected IResponseEnum iResponseEnum;

    /**
     * HTTP状态码
     */
    protected Integer httpStatusCode;


    public BaseException() {
        super();
    }

    public BaseException(IResponseEnum errorInterface) {
        this(errorInterface, null, null, null);
    }

    public BaseException(IResponseEnum errorInterface, String message) {
        this(errorInterface, message, null);
    }

    public BaseException(IResponseEnum errorInterface, String message, Integer httpStatusCode) {
        this(errorInterface, message, null, httpStatusCode);
    }

    public BaseException(IResponseEnum errorInterface, Throwable cause) {
        this(errorInterface, null, cause, null);
    }

    public BaseException(IResponseEnum errorInterface, String message, Throwable cause, Integer httpStatusCode) {
        super(errorInterface.getMessage(), cause);
        this.iResponseEnum = errorInterface;
        this.code = errorInterface.getCode();
        if (StrUtil.isEmpty(message)) {
            message = errorInterface.getMessage();
        }
        this.message = message;
        this.httpStatusCode = httpStatusCode;
    }

    public BaseException(String message) {
        super(message);
        this.message = message;
    }

    public BaseException(int code, String message) {
        super(message);
        this.code = code;
        this.message = message;
    }

    public BaseException(int code, String message, Throwable cause) {
        super(message, cause);
        this.code = code;
        this.message = message;
    }

    public int getCode() {
        return code;
    }

    public void setCode(int code) {
        this.code = code;
    }

    @Override
    public String getMessage() {
        return message;
    }

    public void setMessage(String msg) {
        this.message = message;
    }

    public IResponseEnum getResponseEnum() {
        return iResponseEnum;
    }

    public Integer getHttpStatusCode() {
        return httpStatusCode;
    }

    public void setHttpStatusCode(Integer httpStatusCode) {
        this.httpStatusCode = httpStatusCode;
    }

    @Override
    public String toString() {
        return "BaseException [code=" + code + ", message=" + message + "]";
    }
}
